package com.hqbzl.chat.handler;

import com.hqbzl.chat.factory.Factory;
import com.hqbzl.chat.model.GExitGroupMessage;
import com.hqbzl.chat.model.Group;

import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

@Sharable
public final class GroupExitMessageHandler extends SimpleChannelInboundHandler<GExitGroupMessage> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, GExitGroupMessage msg) throws Exception {
		String groupName = msg.getGroupName();
		String userName = msg.getUserName();
		Group group = Factory.groupSession.removeMember(groupName, userName);
		ctx.writeAndFlush(group);
	}
}